package kuangshen.sleep;

/**
 * @program: liangt
 * @description: 模拟网络延时，放大问题的发生性
 * @author: liangt
 * @create: 2021-03-01 16:25
 */
public class TestSleep implements Runnable {

    private int ticketNumber = 10;

    @Override
    public void run() {
        while (true){
            if (ticketNumber <= 0){
                break;
            }
            try {
                Thread.sleep(100);
            }catch (Exception e){
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "-->拿到了第"+ ticketNumber-- +"张票");
        }
    }

    public static void main(String[] args) {
        TestSleep testSleep = new TestSleep();

        new Thread(testSleep,"张老师").start();
        new Thread(testSleep,"芩老师").start();
        new Thread(testSleep,"王老师").start();
    }
}
